package com.zsxb.crm.controller;

import com.zsxb.crm.annotation.Log;
import com.zsxb.crm.dto.MenuPageDTO;
import com.zsxb.crm.pojo.Menu;
import com.zsxb.crm.result.Result;
import com.zsxb.crm.service.MenuService;
import com.zsxb.crm.vo.MenuVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/system/menu")
@Slf4j
public class MenuController {
    @Autowired
    private MenuService menuService;

    /**
     * 菜单管理分页查询
     */
    @GetMapping("list")
    public Result<List<Menu>> list(MenuPageDTO menuPageDTO){
        List<Menu> menu =  menuService.queryAll(menuPageDTO);
        return Result.success(menu);
    }

    /**
     * 菜单栏新增
     */
    @PostMapping
    @Log
    public Result<String > insert(@RequestBody Menu menu){
        menuService.insert(menu);
        return Result.success();
    }

    /**
     * 菜单栏删除
     */
    @DeleteMapping("/{menuId}")
    @Log
    public Result<String> delete(@PathVariable Long menuId){
        menuService.delete(menuId);
        return Result.success();
    }

    /**
     * 菜单栏修改回显
     */
    @GetMapping("/{menuId}")
    public Result<MenuVO> queryByMenuId(@PathVariable Long menuId){
        MenuVO menu = menuService.queryByMenuId(menuId);
        return Result.success(menu);
    }

    /**
     * 菜单修改
     */
    @PutMapping
    @Log
    public Result<String> update(@RequestBody Menu menu){
        menuService.update(menu);
        return Result.success();
    }



}
